package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.TextView;

import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.bean.SlidingSmallBean;


public class LandsortAdpter extends BaseAdapter {
    private Context mContext;
    private List<SlidingSmallBean.Paramss>  mLists ;
    private LayoutInflater layoutInflater;

    public LandsortAdpter(Context context, List<SlidingSmallBean.Paramss> lists) {
        mContext = context;
        mLists = lists;
        layoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mLists != null ? mLists.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mLists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public void addView(List<SlidingSmallBean.Paramss> ll){
        if(ll.size()<=0){
            return;
        }else{
            mLists.addAll(ll);
        }
    }
//    public void clear(){
//        for (int i = 0; i < mLists.size(); i++) {
//            mLists.get(i).setCheck(false);
//        }
//        notifyDataSetChanged();
//    }
    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(convertView == null){
            convertView= layoutInflater.inflate(R.layout.landsort_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
            AutoUtils.auto(convertView);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.landgood_key.setText(mLists.get(position).getName()+": ");
        LandsortItemAdpter adpter=new LandsortItemAdpter(mContext,mLists.get(position).getChilds());
        holder.landgood_view.setAdapter(adpter);
        adpter.clear();
        return convertView;
    }


    static class ViewHolder{
        @BindView(R.id.landgood_key)
        TextView landgood_key;
        @BindView(R.id.landgood_view)
        GridView landgood_view;


        public ViewHolder(View view){
            ButterKnife.bind(this,view);
        }
    }
}
